//
//  huiyuanDetailsViewController.m
//  daogouApp
//
//  Created by panquanReabam.com on 15-6-2.
//  Copyright (c) 2015年 jiezsoft.com. All rights reserved.
//

#import "MyresultsViewController.h"
#import "HttpRequest.h"
#import <JavaScriptCore/JavaScriptCore.h>
#import "ExhibitionObject.h"
@interface MyresultsViewController ()<MBProgressHUDDelegate,TestDelegate,UIGestureRecognizerDelegate,UIWebViewDelegate,UINavigationControllerDelegate,UITextFieldDelegate>


@end

@implementation MyresultsViewController

{

    UIWebView*webview;
}
@synthesize alt = alt;
-(void)BackAction:(UIButton *)sender{
    
    
    [self.navigationController popViewControllerAnimated:YES];
    
}
- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    
    
    
    self.navigationController.delegate = nil;
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBarHidden=NO;
        self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
       UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.font=[UIFont systemFontOfSize:13];
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.navigationController.delegate = self;
    
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate = self;    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed: @""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];

    

    self.title = @"我的业绩";
    
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     backColor,
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    
    
    
    
    webview  = [[UIWebView   alloc]  initWithFrame:CGRectMake( 0,  0,  ScreenWidth ,  ScreenHeight)];
    webview.scalesPageToFit = TRUE;
    [webview   setUserInteractionEnabled: YES ];	 //是否支持交互
    [webview   setDelegate: self ];				 //委托
    [webview   setOpaque: YES ];

    [webview setNeedsLayout];
    [webview layoutIfNeeded];//透明
    [self.view  addSubview : webview];
//    NSString * path =[NSString stringWithFormat:@"%@",@"http://www.try-shopping.com:88/02%E7%A7%BB%E5%8A%A8%E5%AF%BC%E8%B4%AD/00%E4%BD%93%E9%AA%8C%E8%B4%AD/%E7%BB%BC%E5%90%88%E4%B8%9A%E7%BB%A9.html"];
//    ;
//    [webview loadRequest:[NSURLRequest requestWithURL:[[NSURL alloc] initWithString :path]]];
    [self loadPage];
    
}

- (void)loadPage {

    NSInteger numtime = [NSDate date].timeIntervalSince1970;
    NSString *numtimestr = [NSString stringWithFormat:@"%ld",numtime];
    NSString *str1=[NSString stringWithFormat:@"%d",TARGET_VERSION];
    NSString *plistPath1 = [[NSBundle mainBundle] pathForResource:str1
                                                           ofType:@"plist"];
    NSDictionary *dictionary1 = [[NSDictionary alloc] initWithContentsOfFile:plistPath1];
    //    NSLog(@"dictionary1===%@",dictionary1);
    NSString *serverAddress = [dictionary1 objectForKey:@"ExhibitionUrlHead"];
    NSString *urlStr=[NSString stringWithFormat:@"%@/htmlForApp/report_self_sales.html?v=%@",serverAddress,numtimestr];
    NSURL *url = [[NSURL alloc]initWithString:urlStr];
    [webview loadRequest:[NSURLRequest requestWithURL:url]];
   NSLog(@"------%@",urlStr);
}

- (void)webViewDidStartLoad:(UIWebView *)webView
{

    
    JSContext *context=[webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
    //js调用iOS
    //第一种情况
    //其中test1就是js的方法名称，赋给是一个block 里面是iOS代码
    
    ExhibitionObject *exhiObject=[ExhibitionObject  new];
    exhiObject.delegate=self;
    context[@"appJs"]=exhiObject;
    
    
}

- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
